package com.dzsw.trans.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dzsw.trans.domain.Users;
import com.dzsw.trans.service.IUsersService;
import com.dzsw.trans.mapper.UsersMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author SyDevuser36
 * @description 针对表【users】的数据库操作Service实现
 * @createDate 2025-07-30 14:58:45
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Resource
    private UsersMapper usersMapper;

    @DS("sqlServer")
    @Override
    public List<Users> getAllFromSqlServer() {
        return usersMapper.selectList(new QueryWrapper<>());
    }

    @DS("oracle")
    @Override
    public List<Users> getAllFromOracle() {
        return usersMapper.selectList(new QueryWrapper<>());
    }

    @DS("sqlAnyWhere")
    @Override
    public List<Users> getAllFromSqlAnyWhere() {
        return usersMapper.selectList(new QueryWrapper<>());
    }

    @DS("sqlServer")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteByIdSqlServer(Integer id, Integer sleepSeconds) throws Exception {
        usersMapper.deleteById(id);
        if (sleepSeconds > 0) {
            Thread.sleep(sleepSeconds * 1000);
        }
    }

    @DS("oracle")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteByIdOracle(Integer id, Integer sleepSeconds) throws Exception {
        usersMapper.deleteById(id);
        if (sleepSeconds > 0) {
            Thread.sleep(sleepSeconds * 1000);
        }
    }

    @DS("sqlAnyWhere")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteByIdSqlAnyWhere(Integer id, Integer sleepSeconds) throws Exception {
        usersMapper.deleteById(id);
        if (sleepSeconds > 0) {
            Thread.sleep(sleepSeconds * 1000);
        }
    }
}




